﻿using AutoMapper;
using KingsSharp.Core;
using KingsSharp.Common.Extensions;
using CRM.Admin.Contracts.Dto.Logs;
using CRM.Admin.Contracts.Model.Logs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CRM.Admin.Services.Mappers
{
    public class LogsMapper : IMapper
    {
        public void Register()
        {
            Mapper.CreateMap<LoginLogDto, LoginLog>();
            Mapper.CreateMap<LoginLog, LoginLogDto>()
                .ForMember(a => a.CreatedTime, opt => opt.MapFrom(b => b.CreatedTime != null ? b.CreatedTime.ToSimple() : ""));

            Mapper.CreateMap<BusinessLogDto, BusinessLog>();
            Mapper.CreateMap<BusinessLog, BusinessLogDto>()
                .ForMember(a => a.UserName, opt => opt.MapFrom(b => b.User != null ? b.User.Name : ""))
                .ForMember(a => a.LoginCode, opt => opt.MapFrom(b => b.User != null ? b.User.LoginCode : ""))
                .ForMember(a => a.CreatedTime, opt => opt.MapFrom(b => b.CreatedTime != null ? b.CreatedTime.ToSimple() : ""));
        }
    }
}
